簡體   English   中英

如何檢查在JSF或Primefaces中是否打開了瀏覽器窗口?

[英]How to check whether a Browser Window is Opened or not in JSF or Primefaces?

我正在使用jsfprimefaces

我有一個表格,其中有一個StudentId輸入文本和一個命令鏈接,用於在新的Pop-Up StudentId中查看Student Details ,並顯示要顯示的“ Get命令”按鈕

在此處輸入圖片說明

當我單擊“獲取”按鈕時,我想實現這一目標。

  • 如果之前未打開彈出窗口,則不要打開彈出窗口。
  • 如果彈出窗口已經打開,則使用新的參數刷新該窗口。

這是我的代碼:

查看頁面:

...//js code is below ..

<h:outputText value="StudentId :" />
        <p:inputText value="#{myController.studentId}" >
            <pe:keyFilter mask="num"/>
        </p:inputText>
    <p:commandButton value="Get" actionListener="#{myController.getStudentMarksDetails(myController.studentId)}" >

<p:commandLink onclick="openWindow('http://www.google.com','pageName')" >
        <h:outputText value="Student Info "> 
</p:commandLink>

    ...//Displays Student Marks

我的控制器

public Student getStudentMarksDetails(Long studentId){
     //Some Code to Get the Student Marks

    // I want to Check whether a Pop-Up already exists or not, if pop-up is opened then refresh with this url
    RequestContext.getCurrentInstance().execute("updatePopUpWindow('http://stackoverflow.com','pageName');");

}

我的JS

  var myWindow;
    //Opens in the Same window 
    function openWindow(url, name){
          myWindow = window.open(url, name,'status=no,toolbar=no,location=no,menubar=no,resizable,width=1008,height=690,scrollbars,left=100,top=50,').focus();
    }

    // To check whether a Pop-Up window is opened or not 
    //if the pop-up window with pageName is not Opened before then dont open a Pop-Up.
    //if the pop-up window is already opened, then refresh that window with new arguments.

    function updatePopUpWindow(url, name){
        if(myWindow!=null){
            if(!myWindow.closed){
                 myWindow.close();
            }
        }
     //Check the condition Here
        myWindow = window.open(url, name,'status=no,toolbar=no,location=no,menubar=no,resizable,width=1008,height=690,scrollbars,left=100,top=50,').focus();

    }

我嘗試放置此條件,但沒有用:

if(myWindow.name == name){
                myWindow = window.open(url, name,'status=no,toolbar=no,location=no,menubar=no,resizable,width=1008,height=690,scrollbars,left=100,top=50,').focus();
            }

我提到了許多鏈接 ,但無法解決我需要的方式。

由於JS屬性與瀏覽器無關,因此如何在JQuery實現此問題

更新的注釋:我無法使用PF對話框,因為我不知道該外部服務鏈接的方式和類型以及數據和視圖的類型。 認為我不是獲取學生詳細信息所傳遞的URL的作者。

我認為您可以 (也可能不是)使用PF對話框。 取決於您要在其中顯示的頁面。 我使用以下示例在對話框中顯示外部頁面的內容:

托管豆

@ManagedBean
@ViewScoped
public class Bean {
    private String myURL;

    public Bean() {
        myURL = "http://www.stuba.sk/english.html";
    }

    public void handleUpdateDialog(){
         myURL = "http://www.stuba.sk/english/news/news.html";
    }
    //getters and setters
    ...
}

的xhtml

<h:form>
    <p:commandButton value="Show Dialog" oncomplete="dlg.show();" update="dlgId"/>
    <p:commandButton value="Update Dialog" actionListener="#{bean.handleUpdateDialog}" oncomplete="dlg.show();" update="dlgId"/>

    <p:dialog id="dlgId" widgetVar="dlg">
        <iframe frameborder="0" align="left"
               src="#{bean.myURL}" id="someId" scrolling="auto"
               width="600" height="500">
        </iframe>
    </p:dialog>
</h:form>

如您所見,我在PF對話框中使用了iframe,可以對其進行更新(也可以刷新)。 如果您想這樣使用它,則有一些優點和缺點。 對您來說好消息是您可以刷新此對話框。 但是,此解決方案的主要缺點是,由於“ X-Frame-Options”設置(例如google.com,facebook),許多頁面無法在框架中顯示,因此它不適用於所有外部頁面 .com ...),除非您是該頁面的作者,否則您將不會受到影響。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM