如何使用jQuery打开一个新的HTML页面?

时间:2022-08-09 00:30:31

So, I am using IBM Worklight where I have the main file called file1.html and then I created another html file called file2.html.

所以,我正在使用IBM Worklight,其中我有一个名为file1.html的主文件,然后我创建了另一个名为file2.html的html文件。

I am trying to open file2 but no luck so far. I tried following pieces of code:

我试图打开file2但到目前为止没有运气。我尝试了以下代码:

  1. $(this).load("file2.html");

    $(本).load( “file2.html”);

  2. $("div1").load("file2.html"); //div1 is the id for outer div of file1

    $( “DIV1”)负载( “file2.html”); // div1是file1的外部div的id

  3. WL.App.openUrl("file2.html");

    WL.App.openUrl( “file2.html”);

  4. window.openURL("file2.html");

    window.openURL( “file2.html”);

And none of these worked! Any suggestions?

这些都没有奏效!有什么建议么?

4 个解决方案

#1


4  

If you want to use jQuery, the .load() function is the correct function you are after;

如果你想使用jQuery,.load()函数是你正在使用的正确函数;

But you are missing the # from the div1 id selector in the example 2)

但是你缺少示例2中div1 id选择器的#

This should work:

这应该工作:

$("#div1").load("file2.html");

#2


36  

use window.open("file2.html"); to open on new window,

使用window.open(“file2.html”);在新窗口打开,

or use window.location.href = "file2.html" to open on same window.

或者使用window.location.href =“file2.html”在同一窗口中打开。

#3


6  

Use window.open("file2.html");

使用window.open(“file2.html”);

Syntax

句法

var windowObjectReference = window.open(strUrl, strWindowName[, strWindowFeatures]);

Return value and parameters

返回值和参数

windowObjectReference 

A reference to the newly created window. If the call failed, it will be null. The reference can be used to access properties and methods of the new window provided it complies with Same origin policy security requirements.

对新创建的窗口的引用。如果调用失败,则为null。该引用可用于访问新窗口的属性和方法,前提是它符合Same origin策略安全性要求。

strUrl 

The URL to be loaded in the newly opened window. strUrl can be an HTML document on the web, image file or any resource supported by the browser.

要在新打开的窗口中加载的URL。 strUrl可以是Web上的HTML文档,图像文件或浏览器支持的任何资源。

strWindowName 

A string name for the new window. The name can be used as the target of links and forms using the target attribute of an <a> or <form> element. The name should not contain any blank space. Note that strWindowName does not specify the title of the new window.

新窗口的字符串名称。该名称可以使用

元素的target属性作为链接和表单的目标。名称不应包含任何空格。请注意,strWindowName不指定新窗口的标题。

strWindowFeatures 

Optional parameter listing the features (size, position, scrollbars, etc.) of the new window. The string must not contain any blank space, each feature name and value must be separated by a comma.

可选参数,列出新窗口的功能(大小,位置,滚动条等)。该字符串不得包含任何空格,每个要素名称和值必须用逗号分隔。

#4


1  

You need to use ajax.

你需要使用ajax。

http://api.jquery.com/jQuery.ajax/

http://api.jquery.com/jQuery.ajax/

<code>
$.ajax({
  url: 'ajax/test.html',
  success: function(data) {
    $('.result').html(data);
    alert('Load was performed.');
  }
});
</code>

#1


4  

If you want to use jQuery, the .load() function is the correct function you are after;

如果你想使用jQuery,.load()函数是你正在使用的正确函数;

But you are missing the # from the div1 id selector in the example 2)

但是你缺少示例2中div1 id选择器的#

This should work:

这应该工作:

$("#div1").load("file2.html");

#2


36  

use window.open("file2.html"); to open on new window,

使用window.open(“file2.html”);在新窗口打开,

or use window.location.href = "file2.html" to open on same window.

或者使用window.location.href =“file2.html”在同一窗口中打开。

#3


6  

Use window.open("file2.html");

使用window.open(“file2.html”);

Syntax

句法

var windowObjectReference = window.open(strUrl, strWindowName[, strWindowFeatures]);

Return value and parameters

返回值和参数

windowObjectReference 

A reference to the newly created window. If the call failed, it will be null. The reference can be used to access properties and methods of the new window provided it complies with Same origin policy security requirements.

对新创建的窗口的引用。如果调用失败,则为null。该引用可用于访问新窗口的属性和方法,前提是它符合Same origin策略安全性要求。

strUrl 

The URL to be loaded in the newly opened window. strUrl can be an HTML document on the web, image file or any resource supported by the browser.

要在新打开的窗口中加载的URL。 strUrl可以是Web上的HTML文档,图像文件或浏览器支持的任何资源。

strWindowName 

A string name for the new window. The name can be used as the target of links and forms using the target attribute of an <a> or <form> element. The name should not contain any blank space. Note that strWindowName does not specify the title of the new window.

新窗口的字符串名称。该名称可以使用

元素的target属性作为链接和表单的目标。名称不应包含任何空格。请注意,strWindowName不指定新窗口的标题。

strWindowFeatures 

Optional parameter listing the features (size, position, scrollbars, etc.) of the new window. The string must not contain any blank space, each feature name and value must be separated by a comma.

可选参数,列出新窗口的功能(大小,位置,滚动条等)。该字符串不得包含任何空格,每个要素名称和值必须用逗号分隔。

#4


1  

You need to use ajax.

你需要使用ajax。

http://api.jquery.com/jQuery.ajax/

http://api.jquery.com/jQuery.ajax/

<code>
$.ajax({
  url: 'ajax/test.html',
  success: function(data) {
    $('.result').html(data);
    alert('Load was performed.');
  }
});
</code>