如何使用jQuery打开一个新的HTML页面?
所以,我正在使用IBM Worklight,其中我有一个名为file2.html
的主文件,然后我创建了另一个名为file2.html
html文件。
我试图打开file2但到目前为止没有运气。 我尝试了以下代码:
-
$(this).load("file2.html");
-
$("div1").load("file2.html"); //div1 is the id for outer div of file1
-
WL.App.openUrl("file2.html");
-
window.openURL("file2.html");
这些都没有奏效! 有什么建议?
如果你想使用jQuery,.load()函数是你正在使用的正确函数;
但是你缺少示例2中div1 id选择器的#
这应该工作:
$("#div1").load("file2.html");
使用window.open("file2.html");
在新窗口打开,
或者使用window.location.href = "file2.html"
在同一窗口中打开。
使用window.open(“file2.html”);
句法
var windowObjectReference = window.open(strUrl, strWindowName[, strWindowFeatures]);
返回值和参数
windowObjectReference
对新创建的窗口的引用。 如果调用失败,则为null。 该引用可用于访问新窗口的属性和方法,前提是它符合Same origin策略安全性要求。
strUrl
要在新打开的窗口中加载的URL。 strUrl
可以是Web上的HTML文档,图像文件或浏览器支持的任何资源。
strWindowName
元素的target属性作为链接和表单的目标。 名称不应包含任何空格。 请注意, strWindowName
不指定新窗口的标题。
strWindowFeatures
可选参数,列出新窗口的function(大小,位置,滚动条等)。 该字符串不得包含任何空格,每个要素名称和值必须用逗号分隔。
你需要使用ajax。
http://api.jquery.com/jQuery.ajax/
$.ajax({ url: 'ajax/test.html', success: function(data) { $('.result').html(data); alert('Load was performed.'); } });