2017-08-31 58 views
0

有一個網站,我經常訪問一個擁有多種產品頁面像這樣的:???從URL執行onclick?

product.html訂單id = 1000

product.html訂單id = 1001

product.html訂單ID = 1002

等。

在每個頁面有一個確認按鈕我需要按的..

<a type="button" id="confirm" onclick="confirm(this)" class="lpb" data-orderID="1000"><i class="loading-box" style="display:none"><span class="animate-rotate">&#xe67c;</span></i>Confirm</a> 

我試圖操縱URL將這一提交,因此而不是逛product.html?訂單ID = 1001 我會拜訪像product.html?訂單ID = 1001?ID =確認 但很明顯,我已經不知道如何在到達的..如果網址指向任何地方的支持將是巨大的

感謝

+1

網址導致某處,只是鏈接到那? – Martijn

+0

目前還不清楚你想在這裏完成什麼。你可以在查詢字符串中放入任何你想要的值(雖然它們會被'&'字符分開,而不是附加的''字符),但是你的目標是什麼? – David

+0

當您點擊確認按鈕並重新載入同一頁面時,您想附加'&id = confirm'? –

回答

0

,只是鏈接到(如@Martijn上述評論)。如果沒有或者confirm()做任何重要的事情,你可以使用tampermonkey的腳本。用您正在使用腳本的網站編輯@match <your website url here>

// ==UserScript== 
// @name   New Userscript 
// @namespace http://tampermonkey.net/ 
// @version  0.1 
// @description try to take over the world! 
// @author  You 
// @match  <your website url here> 
// @grant  none 
// ==/UserScript== 

(function() { 
    'use strict'; 
    let el = document.getElementById('confirm'); 
    if (el) el.click(); 
})(); 
0

沒有辦法構建一個URL來加載頁面,然後對其執行JavaScript。

當頁面加載並根據其值進行操作時,您將不得不編輯頁面以檢查location對象。

0

這裏我設置值ID:

<a type="button" id="1000" onclick="confirm(this)" class="lpb" data-orderID="1000"><i class="loading-box" style="display:none"><span class="animate-rotate">&#xe67c;</span></i>Confirm</a> 

給ID來動態的,當你點擊鏈接,然後它會與瀏覽器的URL去:你還可以設置網站的基本路徑。

function confirm(thisEvent,eventName){ 
     var basePath="http://basepath.url.com/"; 
     window.location.href =basePath"product.html?orderid="+eventName.target.id; 
    }