使用小书签来跟踪包裹

发布于 2024-08-27 15:42:52 字数 1088 浏览 1 评论 0原文

我正在尝试编写一个小书签来跟踪邮件中的包裹。首先,它检查跟踪页面是否打开,如果没有打开,则在新选项卡中打开它,然后将表单的值设置为跟踪号码。最后,它提交表单。到目前为止,我无法做的是在书签打开新选项卡的情况下设置表单的值。

这是我所拥有的:

javascript: (函数(){
vartrackingNumber = "/*追踪号码*/";
var a = document.forms.trackingForm;
if ('http://fedex.com/Tracking' == document.location) {
trackingForm.trackNbrs.value=trackingNumber;
document.forms.trackingForm.submit();
}
否则{
window.open('http://fedex.com/Tracking');
this.window.onload = function(){ //这似乎是问题
trackingForm.trackNbrs.value=trackingNumber;
onload(document.forms.trackingForm.submit());
}
}
})();

有什么想法吗?

I'm trying to write a bookmarklet that tracks a package in the mail. First it checks to see if the tracking page is open, if not it opens it in a new tab, and then sets the value of the form to the tracking number. Finally, it submits the form. What I'm so far unable to do is set the value of the form in the case where the bookmarklet opens up a new tab.

Here's what I have:

javascript: (function(){
var trackingNumber = "/*tracking number*/";
var a = document.forms.trackingForm;
if ('http://fedex.com/Tracking' == document.location) {
trackingForm.trackNbrs.value = trackingNumber;
document.forms.trackingForm.submit();
}
else {
window.open('http://fedex.com/Tracking');
this.window.onload = function(){ //This seems to be the problem
trackingForm.trackNbrs.value = trackingNumber;
onload(document.forms.trackingForm.submit());
}
}
})();

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

z祗昰~ 2024-09-03 15:42:52

window.open 打开一个新窗口,因此如果这完全可以工作(我对书签没有什么经验),您将必须直接处理新窗口。像这样的东西:

else {
new_window = window.open('http://fedex.com/Tracking');
new_window.onload = function(){ 
new_window.document.trackingForm.trackNbrs.value = trackingNumber;
new_window.document.forms.trackingForm.submit(); 
// I didn't get at all what the onload() was for, re-add if necessary
}

window.open opens a new window, so if this is going to work at all (I have little experience with bookmarklets), you would have to address the new window directly. Something like this:

else {
new_window = window.open('http://fedex.com/Tracking');
new_window.onload = function(){ 
new_window.document.trackingForm.trackNbrs.value = trackingNumber;
new_window.document.forms.trackingForm.submit(); 
// I didn't get at all what the onload() was for, re-add if necessary
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文