简体   繁体   English

使用jQuery导航离开页面

[英]Use jQuery to navigate away from page

I will only have a relative link available to me but I want to use jQuery to navigate to this rel link. 我只会有一个相对链接,但我想使用jQuery导航到这个rel链接。 I only see AJAX functionality in jQuery. 我只在jQuery中看到AJAX功能。 How can I do this using jQuery or just pure HTML/JavaScript? 我怎么能用jQuery或纯HTML / JavaScript做到这一点?

window.location.href = "/somewhere/else";

你不需要jQuery,简单的window.location代码会这样做,例如:

window.location.href = myUrl;

Other answers rightly point out that there is no need to use jQuery in order to navigate to another URL; 其他答案正确地指出,没有必要使用jQuery导航到另一个URL; that's why there's no jQuery function which does so! 这就是为什么没有jQuery函数这样做的原因!

If you're asking how to click a link via jQuery then assuming you have markup which looks like: 如果您正在询问如何通过jQuery单击链接,那么假设您有标记,如下所示:

<a id="my-link" href="/relative/path.html">Click Me!</a>

You could click() it by executing: 您可以通过执行以下命令来click()它:

$('#my-link').click();
window.location = myUrl;

无论如何,这不是jQuery:它是简单的javascript

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用JS / jquery确认何时离开页面 - How to use JS/jquery to confirm when navigating away from page 如何在锚定href中利用javascript而不浏览页面 - how to utilize javascript in the anchor href and not navigate away from the page 远离页面或页面刷新导航时的React.js触发事件 - React.js fire event on navigate away from page or page refresh ASP.NET-从页面导航离开时显示弹出窗口,然后单击“确定”转到特定页面 - ASP.NET - Show a pop up when navigate away from the page and On click of OK go to a specific page 如果我离开页面并返回该页面,更改将消失-Ionic App - Changes disappear if I navigate away from page and comeback to that page - Ionic App 如何处理关闭页面上的“您确定要离开此页面”吗? - How to handle 'Are you sure you want to navigate away from this page' on page close? 用户在JavaScript中离开之前的HTML页面后会怎样? - What happens with previous HTML page after users navigate away from it in JavaScript? 如果文本框包含文本,则不允许用户离开页面 - do not allow user to navigate away from page if text box contains text 如何在浏览器中制作“您确定要离开此页面”警告消息吗? - How to make the 'Are you sure you want to navigate away from this page' warning message in browser? 如何防止“您确定要离开此页面吗?”表单提交时提醒? - How to prevent “Are you sure you want to navigate away from this page?” alert on form submission?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM