Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open a new HTML page using jQuery?

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.

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

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

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

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

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

And none of these worked! Any suggestions?

like image 506
Cute_Ninja Avatar asked Oct 19 '12 23:10

Cute_Ninja


People also ask

How do I add a page in HTML?

To load external HTML into a <div>, wrap your code inside the load() function. To load a page in div in jQuery, use the load() method.

How do I get jQuery to work in HTML?

Step 1: Open the HTML file in which you want to add your jQuery with the help of CDN. Step 2: Add <script> tag between the head tag and the title tag which will specify the src attribute for adding your jQuery. Step 3: After that, you have to add the following path in the src attribute of the script tag.

How do I open a new HTML file in JavaScript?

use location. href = "page2. html"; if you want to open a page in the same window. The OP is asking for a new tab, not the current page nor popup.

How do I move one HTML page to another using JavaScript?

Answer: Use the JavaScript window. location Propertylocation property to make a page redirect, you don't need any jQuery for this. If you want to redirect the user from one page to another automatically, you can use the syntax window. location. replace("page_url") .


2 Answers

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

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

like image 192
Habibillah Avatar answered Oct 06 '22 20:10

Habibillah


Use 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.

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.

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.

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.

like image 36
btiernay Avatar answered Oct 06 '22 18:10

btiernay