JavaScript to implement a simple example of opening a linked page _javascript tips

Source: Internet
Author: User

Links in the page in addition to the normal way, if you use JavaScript, there are many ways, here are some ways to use JavaScript, open the link:

1. Open the link using the window's Open method, which opens the link in the development page, and can also customize the size of the open page, and so on.

<a href= "Javascript:window.open (' http://www.jb51.net ', ' _self ')" > Open a link 1</a><br/>

2. Use of document. URL property to call the new page. Not enough of this approach seems to be ineffective in Firefox.

<a href= "Javascript:document. URL = ' http://www.jb51.net ' > Open a link 2</a><br/>

3. Use Location's property href to open the link.

<a href= "javascript:window.location.href= ' http://www.jb51.net '" > Open a link 3 </a><br/>

4. Use the location method assign to open the link, this effect is the same as in the previous way.

<a href= "javascript:window.location.assign (' http://www.jb51.net ')" > Open a link 4</a><br/>

5. Using the location method replace to open the link is slightly different from the previous assign method, except that the URL of the page that is substituted when you use replace will not go into the history object. That means you can't go back to the page you're replacing.

<a href= "Javascript:window.location.replace (' http://www.jb51.net ')" > Open a link 5</a><br/>

6. Normal links, of course, this is the most friendly way to search engines, you can also do the specified link open window. Only in this way can the linked pages be crawled by search engine spiders.

<a href= "Http://www.jb51.net" > Open a link 5</a><br/>

The above JavaScript to achieve the opening of the link page is a simple example of the small series to share all the content, hope to give you a reference, but also hope that we support the cloud habitat community.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.