背景は次のとおりです。検索フィールドを使用して関連するリンクのリストを検索し、ユーザーの設定に基づいて、検索したリンクを同じページの div または新しいページに表示する Javascript 関数を作成しました。 _blank を使用したウィンドウ。
私の問題は、ユーザーが新しいタブではなく div 内でページをロードすることを選択した場合でも、ページ全体の URL を引き続き表示できるようにすることであることにすぐに気付きました。URL をコピー/貼り付けできるようにしてほしい。完全なリンクを作成するJavascript関数をすでに取得しているので、「document.getElementByID('IDHERE').value =processedPage;」を追加するだけだと思いましたが、それは(何らかの理由で)そうではないようです働く?
以下は、参照用の私の Javascript です。
/* Function to go jump to a user guide */
function goTo() {
var searchAgainst = document.getElementById('guidesSearch').value; // get the search value
nWT_check = localStorage.getItem('newWindowToggle');
var processedPage = 'http://update.my-site.com/onlinehelp/';
var findFlag = 0;
for (i=0; i<allGuides.length; i++) {
if (searchAgainst == allGuides[i]) {
findFlag = 1;
processedPage += allURLs[i];
if (nWT_check == '0') { //Check against the site options
alert(processedPage); // ALERT to see if processedPage is correct. It is, and this alert triggers.
document.getElementById('guidesLink').value = processedPage; // This does not seem to trigger?
document.getElementById('guidesFrame').src = processedPage; // But then this does, which loads the new page in the DIV.
}
else if (nWT_check == '1') {
window.open(processedPage,'_blank');
}
}
}
if (findFlag == 0) {
$('#notFoundModal').modal();
}
}
なので基本的には localStorage の項目を見て、0ならDIV、1ならnew pageを行う。if (nWT_check == '0') { //サイト オプション部分と照合してデバッグしようとしています。
私は毎回、知識が貴重であり、複雑なコードを常にデバッグする時間がないことを知っていますが、私が間違っている可能性があることや、これにどのようにアプローチするかについての洞察は大歓迎です.